package com.whut.clcommon.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 配置Redisson客户端
 * @Author: Zonghe Wang
 * @Date: 2025/5/3 16:52
 */
@Configuration
public class RedisConfig {

    @Value("${cl.redis.host}")
    private String redisHost;

    @Value("${cl.redis.port}")
    private String redisPort;

    @Value("${cl.redis.password}")
    private String redisPassword;

    @Value("${cl.redis.database}")
    private Integer redisDatabase;

/*
  //测试使用
    private String redisHost="8.156.73.223";

    private String redisPort="6379";

    private String redisPassword="123";

    private Integer redisDatabase=0;
*/

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        // 添加redis地址，单点地址，后续可以使用config.useClusterServers()添加集群地址
        config.useSingleServer().setAddress("redis://" + redisHost + ":" + redisPort).setPassword(redisPassword).setDatabase(redisDatabase);
        // 创建客户端
        return Redisson.create(config);
    }

}
